import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

""" 无头模式
# 1. 打开浏览器驱动管理
ChromeIns = ChromeDriverManager().install()
# 2. 创建谷歌浏览器对象并设置无头模式
options = webdriver.ChromeOptions()
options.add_argument('-headless')
driver = webdriver.Chrome(service=Service(ChromeIns), options=options)
# 3. 输入百度网址
driver.get('https://www.baidu.com')
# 4. 获取标题和URL
time.sleep(2)
print(driver.title)
print(driver.current_url)
# 5. 关闭浏览器
driver.quit()
"""

# 1. 打开浏览器驱动管理
ChromeIns = ChromeDriverManager().install()
# 2. 创建谷歌浏览器对象并设置参数：“eager”
options = webdriver.ChromeOptions()
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(service=Service(ChromeIns), options=options)
# 3. 输入百度网址
driver.get('https://v.qq.com/channel/choice')
time.sleep(2)
# 4. 获取标题和URL
text = driver.find_element(By.CSS_SELECTOR, '#app > div.channel.choice > div:nth-child(2) > div > div.banner-list-wrap.horizontal-list > div:nth-child(2) > div.twice-title-area.canHoverAreaStyle > span').text
print(text)
# 5. 关闭浏览器
driver.quit()